home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 117 / MacAddict 117.dmg / Software / Internet & Communication / Snak 5.1 (shareware).dmg / Snak.app / Contents / Resources / Scripts / Dice.txt < prev    next >
Text File  |  2006-02-01  |  2KB  |  71 lines

  1. # Kent Sorensen 06/09/00 This file contains an alias useful in online role playing games etc.
  2.  
  3. # /dice "number of dice" "number of sides" "modifier"
  4.  
  5. # in script : $0 : number of dice
  6. #             : $1 : number of sides
  7. #             : $2 : modifier
  8.  
  9. # output examples
  10. # /dice 2 6 0
  11. # <yournick> rolls 2 d 6 = 3,3 = 6
  12.  
  13. # /dice 2 6 10
  14. # <yournick> rolls 2 d 6 + 10 = 3,1 + 10 =  14
  15.  
  16. # A "gotcha" of the ircII language is that if you use the @ form instead of the
  17. # assign command, the parameters have no $ making it just 0 instead of $0
  18.  
  19. # use the @ form when you use the variable is an arithmetic expression like
  20. # this @eyes = eyes + 1
  21.  
  22. # the [] around some elements cause them to be 'evaluated' meaning that
  23. # the contents of variables are used instead of the name of the variable
  24.  
  25. alias dice {
  26.     if ([$-] != "")
  27.     {
  28.         ^assign dices $0
  29.         
  30.      # get a random number between zero and one less than $1
  31.          ^assign eyes $rand($1)  
  32.          
  33.     # compensate for the zero base
  34.           @eyes = eyes + 1        
  35.            
  36.      # create output string and treat as string, not number      
  37.         ^assign outputString ${eyes}
  38.         @outputSum = eyes + [$2]
  39.         
  40.         
  41.      # the first dice was handled above, deal with the rest and build comma separated list
  42.            
  43.         ^assign repcnt $0
  44.         while ( repcnt > 1 )
  45.         {
  46.             ^assign eyes $rand($1)
  47.               @eyes = eyes + 1
  48.               
  49.      # concatenate output string as string, not number      
  50.             ^assign outputString $outputString,${eyes}
  51.               @outputSum = outputSum + eyes
  52.         
  53.             @repcnt = repcnt - 1
  54.         }
  55.         ^assign -repcnt
  56.         
  57.         if ([$2] > 0)
  58.         {
  59.             me rolls $0 d $1 + $2 = $outputString + $2 = $outputSum
  60.         }
  61.         {
  62.             me rolls $0 d $1 = $outputString = $outputSum
  63.         }
  64.     }
  65.     {
  66.         echo Dice syntax is <number of dice> <number of sides> <modifier>
  67.     }
  68. }
  69.  
  70. echo Dice script loaded. Syntax is /dice <number of dice> <number of sides> <modifier>
  71.